package com.shardingjdbc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shardingjdbc.entity.Book;
import com.shardingjdbc.mapper.BookMapper;
import com.shardingjdbc.service.BookService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhanglei01
 * @date 2020/9/21 17:18
 */
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {

    @Override
    public List<Book> getBookList() {
        return baseMapper.selectList(Wrappers.<Book>lambdaQuery());
    }

    @Override
    public IPage<Book> getBookListPage(Integer page, Integer limit) {

        Page<Book> platformPage = new Page<>(page, limit);
        QueryWrapper<Book> qw = new QueryWrapper<>();
        qw.orderByAsc("id");
        IPage<Book> operationPage = this.page(platformPage, qw);

        return operationPage;
    }

    @Override
    public boolean save(Book book) {
        return super.save(book);
    }
}
